using System;
using System.Web;
using System.Web.Security;

namespace AUSRIS.Reports.Extensions.Security.Authentication
{
	/// <summary>
	/// Implementation of IAuthenticationProvider
	/// that uses System.Web.Security.Membership authentication
	/// </summary>
	public class ASPNETMembershipAuthenticationProvider : IAuthenticationProvider
	{
		#region IAuthenticationProvider Members

		public string GetUsername(HttpContext context)
		{
			string username = context.Request.Form["USERNAME"];
			string password = context.Request.Form["PASSWORD"];
			if ( Membership.ValidateUser(username, password) )
			{
				return username;
			}
			else
			{
				return string.Empty;
			}
		}

		public string GetRedirectUrl(HttpContext context)
		{
			throw new InvalidOperationException("GetRedirectUrl should not be used with " + this.GetType().Name);
		}

		public bool IsUIEnabled
		{
			get
			{
				return true;
			}
		}

		#endregion
	}
}
